package com.explorati.interview.interview.chapterfifteen.sort;

import java.util.Random;

public class SortTest {
	public static void main(String[] args) {
		int n = 10000;

		// 需要用Integer，不能用int
		Integer[] arr1 = SortTestHelper.generateNearlyOrderArray(10000, 50);
		Integer[] arr3 = SortTestHelper.copyIntArray(arr1);
		Integer[] arr5 = SortTestHelper.copyIntArray(arr1);
		SSortVersion2 s = new SSortVersion2();
		SortTestHelper.testSort("SelectionSort", s, arr1);
		SortTestHelper sh = new SortTestHelper();
		if (sh.isSorted(arr1)) {
			System.out.println("isSorted");
		} else {
			System.out.println("not sorted");
		}
		// s.sort(arr1);
		// SortTestHelper.printArray(arr1);

		Sort s2 = new InsertSortV2();
		SortTestHelper.testSort("InsertSortVersion2", s2, arr3);
		if (sh.isSorted(arr3)) {
			System.out.println("isSorted");
		} else {
			System.out.println("not sorted");
		}

		Sort s1 = new InsertSort();
		SortTestHelper.testSort("InsertSort", s1, arr5);
		if (sh.isSorted(arr5)) {
			System.out.println("isSorted");
		} else {
			System.out.println("not sorted");
		}

		MergeSort ms = new MergeSort();
		int[] arr6 = new int[35];
		Random rand = new Random();
		for (int i = 0; i < arr6.length; i++) {
			arr6[i] = rand.nextInt(10000);
		}
		long startTime = System.nanoTime();
		ms.sort(arr6);
		long endTime = System.nanoTime();

		System.out.println("MergeSort " + " :" + (endTime - startTime) / 1000000000.0 + "s");

		boolean flag = true;
		for (int i = 0; i < arr6.length - 1; i++) {
			if (arr6[i] > arr6[i + 1]) {
				flag = false;
			}
		}
		if (flag) {
			System.out.println("isSorted");
		} else {
			System.out.println("not sorted");
		}

		Float[] arr2 = { (float) 5.3, (float) 3.5, (float) 3.6, (float) 7.4, (float) 9.7, (float) 9.8 };
		s.sort(arr2);
		for (float i : arr2) {
			System.out.print(i + "\t");
		}

		System.out.println();

		String[] strs = { "I", "am", "a", "good", "boy" };
		s.sort(strs);
		for (String str : strs) {
			System.out.print(str + "\t");
		}

		System.out.println();

		Student stu1 = new Student("张三", 1);
		Student stu2 = new Student("李四", 8);
		Student stu3 = new Student("王五", 3);
		Student[] students = { stu1, stu2, stu3 };
		s.sort(students);
		for (Student stu : students) {
			System.out.print(stu.getName() + "\t");
		}
	}
}
